import Head from 'next/head';
import { InstallCommand } from '../../../components/mdx/InstallCommand';
import { FAQs } from '../../../components/mdx/FAQs';
import { Alert } from '@mantine/core';
import { IconInfoCircle } from '@tabler/icons-react';

<Head>
  <title>{'Installation - Mantine React Table Docs V2'}</title>
  <meta name="description" content="How to install Mantine React Table" />
</Head>

> This is the install guide for `mantine-react-table` **V2** and `@mantine/` packages **V7**. MRT V2 will not work with Mantine V6.

<Alert variant="light" color="orange" icon={<IconInfoCircle />}>
  Mantine React Table V2 is still a work in progress, but we are making good
  progress every day.
</Alert>

## Installation

> `mantine-react-table` V2 requires **Mantine V7.3+** packages as dependencies in your project.
>
> If you are already using Mantine, you probably already have most of these peer dependencies installed.
>
> Just double-check that you have the following in your package.json, or use the [full install commands](<#install-with-required-peer-dependencies-(recommended)>) below.
>
> 1.  `@mantine/core` (^v7.3+)
> 2.  `@mantine/hooks` (^v7.3+)
> 3.  `@mantine/dates` (^v7.3+)
> 4.  `@tabler/icons-react` (2.23.0+)
> 5.  `dayjs` (v1.11+)
> 6.  `clsx` (v2+)
> 7.  `react` and `react-dom` (v18)

### Quick Install

The Quick Install instructions here assume you already have Mantine V7 installed and correctly configured with postcss in your project.

<InstallCommand packagesString="mantine-react-table@beta" />

### Install With Required Peer Dependencies (Recommended)

It is best to refer to the [Mantine V7 installation guide](https://mantine.dev/getting-started/) for the most up-to-date instructions on how to install Mantine V7 for your specific React meta framework. (Next.js, Remix, Vite, etc.)

#### Install Mantine React Table with Mantine required peer dependencies:

<InstallCommand />
<br />

> You do NOT need to install `@tanstack/react-table`, as it is already an internal dependency of `mantine-react-table`, and must use an exact version already specified internally.
>
> All internal dependencies: `@tanstack/react-table`, `@tanstack/react-virtual`, and `@tanstack/match-sorter-utils`

#### Install PostCSS dev dependencies (Optional)

If you are using Mantine V7, it is common to use CSS modules for advanced custom styling. You may want to install and configure PostCSS like down below, but it is not required if you are using a different styling solution.

<InstallCommand packagesString="-D postcss postcss-preset-mantine postcss-simple-vars" />
<br />

Create a `postcss.config.cjs` file in the root of your project with the following contents:

```js
module.exports = {
  plugins: {
    'postcss-preset-mantine': {},
    'postcss-simple-vars': {
      variables: {
        'mantine-breakpoint-xs': '36em',
        'mantine-breakpoint-sm': '48em',
        'mantine-breakpoint-md': '62em',
        'mantine-breakpoint-lg': '75em',
        'mantine-breakpoint-xl': '88em',
      },
    },
  },
};
```

<br />

### Setup Mantine Theme

The [Mantine V7 installation guide](https://mantine.dev/getting-started/) has much better instructions for how to set up your Mantine theme, but you should have something like this in your project:

```tsx
import { MantineProvider, createTheme } from '@mantine/core';

const theme = createTheme({
  /** Put your mantine theme override here */
});

function Demo() {
  return (
    <MantineProvider theme={theme}>
      <App />
    </MantineProvider>
  );
}
```

### Import CSS Styles

After you install mantine-react-table, you will need to import the CSS styles from `mantine-react-table/styles.css` at the root of your project. (Where you import your other Mantine CSS styles.)

```js
import '@mantine/core/styles.css'; //import Mantine V7 styles needed by MRT
import '@mantine/dates/styles.css'; //if using mantine date picker features
import 'mantine-react-table/styles.css'; //import MRT styles
```

### Common Errors

If you don't see any styles applied to the mantine table components, you may have mismatching versions of `mantine-react-table` and `@mantine/core`. MRT v1 requires Mantine v6 and will not work with Mantine v7. MRT v2 will be released by the end of 2023 and will work with Mantine v7.

Also, if the Action Icon Buttons all have a filled color, that is a good sign that you simply forgot to import the MRT CSS file in the step above.

If you get an error like this:

```bash
"Error: Element type is invalid: expected a string (for built-in components)
or a class/function (for composite components) but got: undefined.
You likely forgot to export your component from the file it's defined in,
or you might have mixed up default and named imports.
```

You probably do not have the correct version of Mantine or Tabler Icons installed.

Make sure all mantine packages are at least v7.3.

Make sure that the `@tabler/icons-react` package is at least v2.23.0.

If you are using an older version of `webpack` or `create-react-app` and get an error like this:

```bash
./node_modules/@tanstack/virtual-core/build/lib/index.esm.js 147:92
Module parse failed: Unexpected token (147:92)
File was processed with these loaders:
```

Then try upgrading either `webpack` or `react-scripts` to the latest versions.

### FAQs

<FAQs
  faqStructuredData={{
    '@context': 'https://schema.org',
    '@type': 'FAQPage',
    mainEntity: [
      {
        '@type': 'Question',
        name: 'Does Mantine V5 Work with Mantine React Table?',
        acceptedAnswer: {
          '@type': 'Answer',
          text: 'The last version of MRT that worked with Mantine V5 was v0.9.5. You can try it out, but it is not recommended as v0 will receive no further updates. Many features and bugfixes are only present in MRT v1. MRT v1 requires Mantine V6.',
        },
      },
      {
        '@type': 'Question',
        name: 'Does Mantine V7 Work with Mantine React Table?',
        acceptedAnswer: {
          '@type': 'Answer',
          text: 'Eventually. MRT v2 will be completely rewritten to use Mantine v7. This should be available by the end of 2023.',
        },
      },
      {
        '@type': 'Question',
        name: 'What is the difference between Mantine React Table and Material React Table?',
        acceptedAnswer: {
          '@type': 'Answer',
          text: 'Mantine React Table and Material React Table are sister libraries. Mantine React Table was forked from Material React Table after its initial success. Mantine React Table uses Mantine instead of Material UI.',
        },
      },
      {
        '@type': 'Question',
        name: "Should I install '@tanstack/react-table' in my package.json for Mantine React Table?",
        acceptedAnswer: {
          '@type': 'Answer',
          text: "<p><b>No</b>, you do not need to install TanStack Table in your project manually, as the latest TanStack Table version automatically gets installed under the hood by MRT itself as an internal dependency. You can import s and functions from '@tanstack/react-table' too.</p>",
        },
      },
      {
        '@type': 'Question',
        name: 'Is TypeScript required to use Mantine React Table?',
        acceptedAnswer: {
          '@type': 'Answer',
          text: '<p><b>No</b>, TypeScript is <b>not required</b> to use Mantine React Table, but it is a whole lot easier to use Mantine React Table with TypeScript, <b>especially when defining columns</b>. If you do use TypeScript, try to keep the latest TypeScript version installed, or at least <b>TS version 4.8</b> or higher.</p>',
        },
      },
    ],
  }}
/>
